#ifndef _LIBFTP_INL_H__
#define _LIBFTP_INL_H__

#include <stdio.h>
#include <string.h>
#include <string>

#if (defined(_MSC_VER))

#define PATH_HR '\\'
#define ftp_msg printf("[INFO] [%s:%5d]", NULL == strrchr(__FILE__, PATH_HR)? __FILE__:(char *)(strrchr(__FILE__, PATH_HR) + 1),__LINE__);printf
#define ftp_warn printf("\033[1;33m[WARNING] [%s:%5d] \033[m", NULL == strrchr(__FILE__, PATH_HR)? __FILE__:(char *)(strrchr(__FILE__, PATH_HR) + 1),__LINE__);printf
#define ftp_error printf("\033[0;32;31m[ERR] [%s:%5d] \033[m", NULL == strrchr(__FILE__, PATH_HR)? __FILE__:(char *)(strrchr(__FILE__, PATH_HR) + 1),__LINE__);printf

#else

#define ftp_msg(fmt, args...) printf("\033[0;32;32m[INFO] [%s:%5d] " fmt"\033[m", basename((char *)__FILE__),__LINE__,## args);
#define ftp_warn(fmt, args...) printf("\033[1;33m[WARNING] [%s:%5d] " fmt"\033[m", basename((char *)__FILE__),__LINE__,## args);
#define ftp_error(fmt, args...) printf("\033[0;32;31m[ERR] [%s:%5d] " fmt"\033[m", basename((char *)__FILE__),__LINE__,## args);

#endif

#ifdef __linux__
#if (__cplusplus < 201103L)
#define nullptr NULL
#endif
#endif

#ifdef MACRO_CXX11

#include <functional>
#include <algorithm>
class ScopeGuard{
public:
	explicit ScopeGuard(std::function<void()> onExitScope)
		:onExitScope_(onExitScope), dismissed_(false)
	{ }
	~ScopeGuard()
	{
		if (!dismissed_) {
			onExitScope_();
		}
	}

	void Dismiss(){
		dismissed_ = true;
	}
private:
	std::function<void()> onExitScope_;
	bool dismissed_;
private: //noncopyable
	ScopeGuard(ScopeGuard const&);
	ScopeGuard& operator=(ScopeGuard const&);
};

#define SCOPEGUARD_LINENAME_CAT(name, line) name##line
#define SCOPEGUARD_LINENAME(name, line) SCOPEGUARD_LINENAME_CAT(name, line)
#define ON_SCOPE_EXIT(callback) ScopeGuard SCOPEGUARD_LINENAME(EXIT, __LINE__)(callback)

#endif

#endif //_LIBFTP_INL_H__